package handler

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"zg6/zk1/doctor-management/api/internal/request"
	"zg6/zk1/doctor-management/common/global"
	"zg6/zk1/doctor-management/common/proto/doctors"
)

func DoctorLogin(c *gin.Context) {
	var req request.DoctorLoginReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	login, err := global.DoctorGrpc.DoctorLogin(c, &doctors.DoctorLoginRequest{
		Account:  req.Account,
		Password: req.Password,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"msg":  "success",
		"data": login,
	})
}

func Plist(c *gin.Context) {
	var req request.PlistReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	login, err := global.DoctorGrpc.Plist(c, &doctors.PlistRequest{
		DoctorId: req.DoctorId,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"msg":  "success",
		"data": login,
	})
}

func PInfo(c *gin.Context) {
	var req request.PInfoReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	info, err := global.DoctorGrpc.PInfo(c, &doctors.PInfoRequest{
		PId: req.PId,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"msg":  "success",
		"data": info,
	})
}
